package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.nio.channels.Channel;
import java.sql.ResultSet;
import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理", tags = "频道管理", description = "频道管理API")
public class AdChannelController {

    //依赖注入
    @Autowired
    private AdChannelService adChannelService;

    @PostMapping("/list")
    @ApiOperation("频道分页列表查询")
    public ResponseResult findPageAndSize(@RequestBody ChannelDTO channelDTO){
        return adChannelService.findByNameAndPage(channelDTO);
    }
    @ApiOperation("频道新增")
    @PostMapping("/save")
    public ResponseResult insertnews(@RequestBody AdChannel channel){
        return adChannelService.insertnews(channel);
    }

    /**
     * 频道修改
     * @param channel
     * @return
     */
    @ApiOperation("频道修改")
    @PostMapping("/update")
    public ResponseResult updatenews(@RequestBody AdChannel channel){
        return adChannelService.updatenews(channel);
    }

    /**
     * 频道删除
     * @param id
     * @return
     */
    @ApiOperation("频道删除")
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id){
        return adChannelService.deletenews(id);
    }

    /**
     * 查询所有的频道数据
     * @return
     */
    @ApiOperation("查询所有的频道数据")
    @GetMapping("/channels")
    public ResponseResult findAllList(){
        List<AdChannel> channelList = adChannelService.list();
        return ResponseResult.okResult(channelList);
    }

    /**
     * 根据id查询频道
     * @param id
     * @return
     */
    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult findById(@PathVariable("id") Integer id){
        return ResponseResult.okResult(adChannelService.getById(id));
    }
}
